package com.chengn.factory;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class MyThreadFactory implements ThreadFactory {
    static AtomicInteger prefixNum = new AtomicInteger(1);

    private static final String THREAD_PREFIX = "my-thread-";

    @Override
    public Thread newThread(Runnable r) {
        String s = THREAD_PREFIX + prefixNum.getAndAdd(1);
        Thread thread = new Thread(r, s);
        System.out.println("构造线程：" + s);
        return thread;
    }
}
